#include "stdafx.h"

namespace xmlredirect
{
	CXmlHandler::CXmlHandler(const pair<string, string>& _TagValue):m_bValueIsFound(false)
	{
		m_TagValues.insert( _TagValue );
	}
	CXmlHandler::~CXmlHandler()
	{}

	void CXmlHandler::startElement(	const XMLCh* const uri,const XMLCh* const localname,const XMLCh* const qname,
				const Attributes& attributes)
	{
		string _tmpNodeName = hc::to_lower( string( xml::X2C(localname)) );
		if ( m_TagValues.find( _tmpNodeName )!= m_TagValues.end() )
		{
			m_currentTagName = _tmpNodeName;
		}
	}
	void CXmlHandler::characters( const XMLCh* const chars, const XMLSize_t length )
	{
		pair< multimap<string,string>::iterator, multimap<string,string>::iterator > ret;
		ret = m_TagValues.equal_range( m_currentTagName ); 
		multimap<string,string>::iterator it = ret.first;
		string value = hc::to_lower( string( xml::X2C(chars) ) );
		for( ; it != ret.second; ++it )
		{
			if ( it->second == value )
				m_bValueIsFound = true;
		}
	}
	void CXmlHandler::endElement( const XMLCh* const uri, const XMLCh* const localname,const XMLCh* const qname )
	{}

	bool CXmlHandler::IsOK()
	{
		return m_bValueIsFound;
	}


}